/* @(#)GSOrderDeptInfoAddAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-16
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import com.hitrust.gs.bean.GSOrderDeptInfoBean;
import com.hitrust.gs.form.GSOrderDeptInfoAddForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.business.GSOrganizationProcessor;
import com.hitrust.gs.util.GenRandNum;
/**
 * 添加
 */
public class GSOrderDeptInfoAddAction extends GSBaseAction{

    public String execute(GSBaseForm aForm) throws Exception {
        GSOrderDeptInfoAddForm tForm = (GSOrderDeptInfoAddForm)aForm;
        try{
        //获得传入的参数
        String   tOrgId = tForm.getGs_org_id();    
       // GSOrderDeptInfoProcessor.permitAdd(tOrgId);
        ArrayList tArrayList=GSOrderDeptInfoProcessor.queryOrderDeptInfo(tOrgId,"");
        int n=tArrayList.size();
        //String[] tAddrId = tForm.getGs_deliver_goods_addr_id();         
        String[] tAddr = tForm.getGs_deliver_goods_addr();         
        String[] tContactName = tForm.getGs_order_contact_name();         
        String[] tContactPhone = tForm.getGs_order_contact_phone();
        //遍历添加
        for(int i=0;i<tAddr.length;i++){
            n++;
            if("".equals(tAddr[i]))
                continue;
            GSOrderDeptInfoBean tGSOrderDeptInfoBean=new GSOrderDeptInfoBean();
            tGSOrderDeptInfoBean.setGs_org_id(tOrgId);
            //tGSOrderDeptInfoBean.setGs_deliver_goods_addr_id(String.valueOf(n));
            tGSOrderDeptInfoBean.setGs_deliver_goods_addr_id(GenRandNum.genDTRandNum());
            tGSOrderDeptInfoBean.setGs_deliver_goods_addr(tAddr[i].trim());
            tGSOrderDeptInfoBean.setGs_order_contact_name(tContactName[i]);
            tGSOrderDeptInfoBean.setGs_order_contact_phone(tContactPhone[i]);
            GSOrderDeptInfoProcessor.addTask(tGSOrderDeptInfoBean);
           }
        }
        catch (GSException err) {
            if(err.getCode() != null ) { 
                HashMap tMap = new HashMap();
                tMap.put("err",err.getMessage());
                aForm.getRequest().setAttribute("_error",tMap);
                aForm.getRequest().setAttribute("exception_desc",err.getMessage());
                aForm.getRequest().setAttribute("exception_code",err.getCode());
                aForm.getRequest().setAttribute("action","A400801");
                //throw new GSException(err.getMessage());
                return GSBaseConstants.FORWARD_ERROR;
            } 
        }
        aForm.getRequest().setAttribute("message", "联系方式添加成功!");
        aForm.getRequest().setAttribute("requery","true");
        ArrayList tAllOraganization = GSOrganizationProcessor.queryManageOrg("","");
        aForm.getRequest().setAttribute("AllOraganization",tAllOraganization);
        //aForm.getRequest().setAttribute("action", "A400403");

        //查询条件
        aForm.getRequest().setAttribute("s_org_id",aForm.getRequest().getParameter("s_org_id"));
        aForm.getRequest().setAttribute("s_gsdelivergoodsaddr",aForm.getRequest().getParameter("s_gsdelivergoodsaddr"));

        
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
